package com.jukte.recipe;

import com.ewhat.recipes.R;
import com.jukte.recipe.utils.AppUtility;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class AboutTabFragment extends Fragment {

	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	private LinearLayout listLayout;
	private LayoutInflater inflater2;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
		if (container == null) {
            // We have different layouts, and in one of them this
            // fragment's containing frame doesn't exist.  The fragment
            // may still be created from its saved state, but there is
            // no reason to try to create its view hierarchy because it
            // won't be displayed.  Note this is not needed -- we could
            // just run the code below, where we would create and return
            // the view hierarchy; it would just never be used.
            return null;
        }
		View view=inflater.inflate(R.layout.frag_about, container,false);
		listLayout=(LinearLayout)view.findViewById(R.id.list_layout);
		inflater2=(LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		loadList();
		return view;
	}
	
	
	private void loadList() {
		View v1=inflater2.inflate(R.layout.row_recipelist, null);
		TextView text=(TextView)v1.findViewById(R.id.toptext);
		ImageView image=(ImageView)v1.findViewById(R.id.rowimage);
		text.setText(R.string.about_page_item1);
		image.setImageResource(R.raw.factsaboutquinoa_menuicon);
		v1.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				getActivity().startActivity(new Intent(getActivity(), FactAboutQuinoaActivity.class));
			}
		});
		listLayout.addView(v1);
		listLayout.addView(getdivider());
		
		
		View v2=inflater2.inflate(R.layout.row_recipelist, null);
		TextView text2=(TextView)v2.findViewById(R.id.toptext);
		ImageView image2=(ImageView)v2.findViewById(R.id.rowimage);
		text2.setText(R.string.about_page_item2);
		image2.setImageResource(R.raw.howtocook_menuicon);
		v2.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				getActivity().startActivity(new Intent(getActivity(), HowToCookQuinoaActivity.class));
			}
		});
		listLayout.addView(v2);
		listLayout.addView(getdivider());
		
		View v3=inflater2.inflate(R.layout.row_recipelist, null);
		TextView text3=(TextView)v3.findViewById(R.id.toptext);
		ImageView image3=(ImageView)v3.findViewById(R.id.rowimage);
		text3.setText(R.string.about_page_item3);
		image3.setImageResource(R.raw.nutrition_menuicon);
		v3.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				getActivity().startActivity(new Intent(getActivity(), QuinoaNutritionActivity.class));
			}
		});
		listLayout.addView(v3);
		listLayout.addView(getdivider());
		
		View v4=inflater2.inflate(R.layout.row_recipelist, null);
		TextView text4=(TextView)v4.findViewById(R.id.toptext);
		ImageView image4=(ImageView)v4.findViewById(R.id.rowimage);
		text4.setText(R.string.about_page_item4);
		image4.setImageResource(R.raw.buyquinoa_menuicon);
		v4.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if(AppUtility.isInternetConnected(getActivity()))
				{
					String url=getActivity().getResources().getString(R.string.buy_quinoa_url);
					Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
					startActivity(browserIntent);
				}
				else
					Toast.makeText(getActivity(), "No Internet Connection!!", Toast.LENGTH_LONG).show();
			}
		});
		listLayout.addView(v4);
		
		listLayout.addView(getdivider());
		
		View v5=inflater2.inflate(R.layout.row_recipelist, null);
		TextView text5=(TextView)v5.findViewById(R.id.toptext);
		ImageView image5=(ImageView)v5.findViewById(R.id.rowimage);
		text5.setText(R.string.about_page_item5);
		image5.setImageResource(R.raw.resources_menuicon);
		v5.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				getActivity().startActivity(new Intent(getActivity(), ResourceGridActivity.class));
			}
		});
		listLayout.addView(v5);
		listLayout.addView(getdivider());
	}

	private View getdivider() {
		// TODO Auto-generated method stub
		View v=new View(getActivity());
		LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 2);
		v.setBackgroundColor(Color.parseColor("#000000"));
		v.setLayoutParams(llp);
		return v;
	}

	

}
